import config
import logging

class RegisterLoginApi:

    # 封装获取图片验证码
    @classmethod
    def get_image_code_api(cls, session, r):
        url = config.Host + f"/common/public/verifycode1/{r}"
        logging.info(f"正在调用获取图片验证码接口:URL={url}")
        resp = session.get(url=url)
        return resp

    # 封装获取短信验证码
    @classmethod
    def get_phone_code_api(cls, session, phone, image_code):
        url = config.Host + "/member/public/sendSms"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"phone": phone, "imgVerifyCode": image_code, "type": "reg"}
        logging.info(f"正在调用获取短信验证码接口：URL={url},请求体body={body}")
        resp = session.post(url=url, headers=header, data=body)
        return resp

    # 封装注册
    @classmethod
    def register_api(cls,session,phone,password,verify_code,phone_code):
        url = config.Host + "/member/public/reg"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"phone": phone, "password": password, "verifycode": verify_code, "phone_code": phone_code,
                "dy_server":"on","invite_phone":""}
        logging.info(f"正在调用注册接口：URL={url},请求体body={body}")
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 封装登录
    @classmethod
    def login_api(cls,session,keywords,password):
        url=config.Host+"/member/public/login"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"keywords":keywords,"password":password}
        logging.info(f"正在调用登录接口：URL={url},请求体body={body}")
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 封装查询登录状态
    @classmethod
    def login_status_api(cls,session):
        url = config.Host+"/member/public/islogin"
        logging.info(f"正在调用查询登录状态接口：url={url}")
        resp = session.post(url)
        return resp
